#ifndef ANT_COLONY_OPTIMIZATION_H
#define ANT_COLONY_OPTIMIZATION_H

#include <QVector>

class AntColonyOptimization {
public:
    // 构造函数
    AntColonyOptimization(const QVector<QVector<double>>& distanceMatrix, int numAnts, int generations, double alpha, double beta, double evaporationRate);

    // 设置和获取函数
    void setNumAnts(int numAnts);
    int getNumAnts() const;

    void setGenerations(int generations);
    int getGenerations() const;

    void setAlpha(double alpha);
    double getAlpha() const;

    void setBeta(double beta);
    double getBeta() const;

    void setEvaporationRate(double rate);
    double getEvaporationRate() const;

    // 蚁群算法求解
    QVector<int> solve();

    double calculateDistance(const QVector<int>& path);

private:
    QVector<QVector<double>> distanceMatrix;
    QVector<QVector<double>> pheromoneMatrix;

    int numAnts;
    int generations;
    double alpha; // 信息素重要性
    double beta;  // 启发信息重要性
    double evaporationRate; // 信息素蒸发率

    int numberOfCities;
    std::vector<QVector<int>> antPaths; // 蚂蚁的路径
    std::vector<double> antPathLengths; // 蚂蚁的路径长度

    // 私有辅助函数

    void initializePheromones();
    void updatePheromones();
    QVector<int> constructSolution(int antIndex);
    int selectNextCity(int currentCity, const QVector<bool>& visited);

};

#endif // ANT_COLONY_OPTIMIZATION_H
